package com.cat.chapter046;

/**
 * @author cat
 * @description https://www.nowcoder.com/practice/545544c060804eceaed0bb84fcd992fb
 * @create 2025/7/15 14:40
 * @since JDK17
 */

import com.cat.test.Main;

import java.io.*;
import java.util.Arrays;
import java.util.HashMap;

public class Solution03 {
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static PrintWriter pr = new PrintWriter(new OutputStreamWriter(System.out));
    static StreamTokenizer tokenizer = new StreamTokenizer(br);
    static int n, m, k, x, sum, ans;
    static HashMap<Integer, Integer> map = new HashMap<>();

    public static void main(String[] args) throws IOException {
        map.clear();
        tokenizer.nextToken();
        n = ((int) tokenizer.nval);
        tokenizer.nextToken();
        k = ((int) tokenizer.nval);
        map.put(0, 0);
        ans = -1;
        sum = 0;
        for (int i = 0; i < n; i++) {
            tokenizer.nextToken();
            x = ((int) tokenizer.nval);
            sum += (x < 0 ? -1 : x > 0 ? 1 : 0); // 求前缀和
            ans = Math.max(ans, i + 1 - map.getOrDefault(-sum, 0));
            if (!map.containsKey(sum)) {
                map.put(sum, i);
            }
        }
        pr.println(ans);
        pr.flush();
        pr.close();
        br.close();
    }
}
